<template>
  <div v-loading="loading" class="app-container">
    <x-table v-model="searchData" :config="tableConfig" :data="tableData" :page="page" :load="getMovieByPage" />
    <el-drawer title="在映影院" :visible.sync="drawer" :direction="direction">
      <span>我来啦!</span>
      <el-button type="primary">查看</el-button>
    </el-drawer>
  </div>


</template>
  
<script>
import { getMovieByPage, delMovieById } from '@/api/movie'
import { getToken } from '@/utils/auth'
import movieForm from './form.vue'
import { importDic } from '@/utils'

export default {
  data() {
    return {
      eSDic: 'findMoviePlayStatus',
      drawer: false,
      direction: 'rtl',
      loading: 0,
      tableData: [],
      page: {
        pageSizes: [10, 20],
        pageSize: 10,
        pageNum: 1,
        total: 0
      },
      searchData: {
        playStatus: 88
      },
      propId: '',
      dialogName: ''
    }
  },

  computed: {
    tableConfig() {
      const _this = this
      return {
        search: true,
        reset: true,
        stripe: false,
        border: true,
        highlightCurrentRow: true,
        rowClick: node => _this.$emit('cellClick', node),
        btn: [
          { text: '新增', click: () => _this.operate2('add'), icon: 'el-icon-circle-plus' }
        ],
        column: [
          { label: '电影名', name: 'movieName', search: true, xType: 'input' },
          { label: '电影类型', name: 'movieType', search: false, xType: 'input' },
          { label: '电影时长(min)', name: 'last', search: false, xType: 'input' },
          // { label: '审核状态', name: 'examineStatus', search: true, xType: 'select', dic: importDic(_this.eSDic) },
          { label: '放映状态', name: 'playStatus', search: true, xType: 'select', dic: importDic('moviePlayStatuss') }
        ],
        operate: [
          { text: '编辑', show: true, click: data => this.operate2('edit', data) },
          { text: '查看', show: true, click: data => this.operate2('detail', data) },
          { text: '删除', show: true, click: _this.del },
          { text: '在映影院', show: true, click: _this.drawerss }
        ]
      }
    }
  },

  mounted() {
    this.getMovieByPage()
  },

  methods: {
    getMovieByPage() {
      this.loading++
      getMovieByPage(this.searchData, this.page.pageNum, this.page.pageSize, getToken()).then(res => {
        console.log("getMovieByPage" + res)
        this.tableData = res.result.records
        this.page.total = res.result.total
      }).catch(e => console.error(e)).finally(() => this.loading--)
    },
    operate(mode, data) {
      if (mode !== 'add') {
        this.propId = data.id
        this.eSDic = 'movieExamineStatus'
      }
      this.mode = mode
      this.dialogName = 'movieForm'
    },
    operate2(mode, data) {
      if (mode !== 'add') {
        this.propId = data.id
      }
      this.mode = mode
      this.$router.push({
        path: "/movie/newForm",
        query: {
          mode: this.mode,
          id: this.propId
        }
      })
    },
    del(data) {
      this.delConfirm().then(() => {
        this.loading++
        delMovieById(data.id, getToken()).then(res => {
          console.log(data.id + 'delMovieById' + res)
          this.$message.success(res.message)
          this.getMovieByPage()
        }).catch(e => console.log(e)).finally(() => this.loading--)
      }).catch(e => console.log(e))
    },
    drawerss() {
      this.drawer = true
    },
    closeDialog() {
      this.dialogName = ''
    }
  },

}
</script>
  